var customerShare = function(){

	
	var userSelector = null;
	var selectUserId = [];
	var userSelector2 = null;
	var selectUserId2 = [];
	var project_id ='-1';	
	var ps = new ProjectSourceDemo();	
	
	//test
	 var individual =  new Ext.form.TextField({
		fieldLabel : '维修人',
		width : 250,
		listeners: {
			   'render': function(cmp) {
					var self = cmp.ownerCt.ownerCt;
					cmp.getEl().on('click', function(){showUser1();}, self); 
				}
			}
	});
	
	var remark = new Ext.form.TextArea({
		fieldLabel : '原因描述',
		width : 840,
		height:200
		
	});
	
	
	// 查询条件---begin
	var searchName = new Ext.form.TextField({
		fieldLabel : '客户名称',
		width : 150
	});
	
	var searchArea = new Ext.form.ComboBox( {
		fieldLabel : '所属区域',
		store: OMS.AREA,
		mode : 'local',
		displayField : 'name',
		triggerAction : 'all',
		editable : false,
		valueField : 'id',
		typeAhead : true,
		width : 150,
		emptyText : '---请选择---',
		selectOnFocus : true
	});
	
		var afterServiceId = new Ext.form.TextField( {
		fieldLabel : '维修单号',
		//hiddenName : 'type',
	
		width : 150
	
	});
	
	var searchComplateDate = new Ext.form.DateField( {
		fieldLabel : '预约时间',
		format : 'Y-m-d',
		width : 150
	});
		var searchEndDate = new Ext.form.DateField( {
		fieldLabel : '至',
		format : 'Y-m-d',
		width : 150
	});
	
	var btn_search = new Ext.Button({
		text : '查询',
		iconCls: 'icon-search',
		handler: function (){afterServiceStore.load();}
	});



	
	var projectHeader = new Ext.form.TextField({
		fieldLabel : '参与领导',
		width : 150
	});
	



	var afterServiceStore = new Ext.data.JsonStore(
			{
				url : '../afterserive/searchAfterOrder.form?status=11&timesnap=' + new Date()
						.getTime(),
				root : 'result',
				fields : [ 'AfterServiceID', 'AFcustomerName', 'AFcustomerArea', 'AFcustomerID',
					 	   'AFserviceStartDate', 'AFconnName', 'AFconnOffTele', 'AFconnMobile', 
					 	   'AFconnEmail', 'CreateBy', 'CreateTime', 'LastUpdateBy', 'LastUpdateTime', 
					 	   'ServicePerson', 'OrderService', 'reason','AFserviceAddress'],
				listeners : {
					scope : this,
					beforeload : function(thiz) {
						thiz.baseParams = {
							searchName : searchName.getValue(),
							searchArea : searchArea.getValue(),
							searchAfterServiceId : afterServiceId.getValue(),
							searchComplateDate : searchComplateDate.getValue() ? searchComplateDate.getValue().format('Y-m-d') : '',
							searchEndDate : searchEndDate.getValue() ? searchEndDate.getValue().format('Y-m-d') : ''
						};
					}
				}
			});
			
	var xg = Ext.grid
	var sm = new xg.CheckboxSelectionModel();		
	var sellGrid = new Ext.grid.GridPanel({
	sm: sm,
		width : 930,
		height : 300,
		store : afterServiceStore,
		scope:this,
		listeners : {
			scope : this,
			rowmousedown : function(grid,index,e){
				var data = grid.store.getAt(index).data;
			}
		},  
			columns : [ sm,
						{header:'回访单编号',sortable: true,width: 50,dataIndex:'AfterServiceID'},
			            {header:'客户编号',sortable: true,width: 50,dataIndex:'AFcustomerID'},
			            {header:'维修人员',sortable: true,width: 150,dataIndex:'ServicePerson'},
					    {header:'客户名称',width: 100, sortable: true,dataIndex:'AFcustomerName'},
					    {header:'联系人',width: 100, sortable: true,dataIndex:'AFconnName'}, 
					    {header:'手机',width: 150, sortable: true,dataIndex:'AFconnMobile'},
					    {header:'办公电话',width: 150, sortable: true,dataIndex:'AFconnOffTele'},
					    {header:'email',width: 150, sortable: true,dataIndex:'AFconnEmail'},
					    {header:'所属区域',width: 100, sortable: true,dataIndex:'AFcustomerArea',renderer:function(value){return OMS.AREA[value];}},
					    {header:'维修地点',sortable: true,dataIndex:'AFserviceAddress'},
					    {header:'预约时间',sortable: true,dataIndex:'AFserviceStartDate'},
					    {header:'原因描述',sortable: true,dataIndex:'reason'}
					    
		         ],
       bbar:new Ext.PagingToolbar({
		 pageSize: 5,
         store: afterServiceStore,
         displayInfo: true,
         displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
         emptyMsg: "没有记录..."
       })
	});
	
	
	
// 在project_main.js 里  items : [ new Draft()<=js名称  .beforeSell  <=  FormPanel 方法]

	this.customerSharePanel = new Ext.form.FormPanel({
		frame : true,
		width : 950,
		fileUpload: true, 
		labelWidth : 85,
		buttons : [{text:'确认提交',iconCls: 'icon-accept',scope:this,handler:function(){
		           	var scope=this;
					Utils.confirm2({
						msg:"是否执行分配？",
					  	width:220,
						fn:function(){
								var count=sellGrid.getSelectionModel().getSelections();
								var ids="";
								if(count<=0){//这里 的逻辑 按照网格里的数据判断的
									alert("请选择数据");
									return false;
									}
								var servicePerson=individual.getValue();
								if(servicePerson==""){
									alert("请选择服务人员");
									return false;
								}
								for(var i=0 ;i<count.length;i++){
									var data = count[i].data['AfterServiceID'];
									ids+=count[i].data['AfterServiceID']+',';
									}
									
								scope.customerSharePanel.getForm().submit({
									waitTitle : '系统提示',
									waitMsg : '数据提交中，请稍候...',
									url:'../afterserive/updateAfterOrder.form?timesnap=' + new Date().getTime()+'&ids='+ids,
									method:'post',
										params:{servicePerson : servicePerson
												},	
										success:function(data){
											Utils.info("分配成功","系统提示");	
											afterServiceStore.load();
												}
									});		
							}
						})
					}
				}],
		items : [{layout:'column',defaults:{layout:'form'},
			      items:[{columnWidth:0.3,items:[searchName]},
			             {columnWidth:0.3,items:[searchArea]},
			             {columnWidth:0.3,items:[afterServiceId]},
			             {columnWidth:0.3,items:[searchComplateDate]},
			             {columnWidth:0.3,items:[searchEndDate]},
			             {columnWidth:0.15,items:[btn_search]}
			             
			             ]
				},sellGrid,individual,remark],
	   listeners: {
	    	render: {fn:function(){ 
	    	
			}}
		}
	});
	var showUser1 = function(){
		selectUserId = [129,3840,20151];
		
		if(userSelector==null){
			userSelector=new Tree.User(selectUserId,function(o){
				setUsers1(o);
			},null,'105');
		}
		userSelector.show();
	};

	var setUsers1 = function(o){
		var names = [];
		selectUserId =[];
		for(var i=0;i<o.length;i++) {
			names.push(o[i].text);
			selectUserId.push(o[i].id);
		}
		individual.setValue(names.join(','));
	};
}